[analytics-engine] Fix CHECKED_LONG_SUM conversion - #22611
Conversation
PR Reviewer Guide 🔍(Review updated until commit d0cc903)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to d0cc903 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit a01e3bd
Suggestions up to commit 6d8cc59
Suggestions up to commit b798c51
Suggestions up to commit 2d8457e
Suggestions up to commit dba238c
|
Signed-off-by: Kai Huang <ahkcs@amazon.com>
dba238c to
2d8457e
Compare
|
Persistent review updated to latest commit 2d8457e |
|
Persistent review updated to latest commit b798c51 |
|
❌ Gradle check result for b798c51: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
Persistent review updated to latest commit 6d8cc59 |
Signed-off-by: Kai Huang <ahkcs@amazon.com>
6d8cc59 to
a01e3bd
Compare
|
Persistent review updated to latest commit a01e3bd |
|
❌ Gradle check result for a01e3bd: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Signed-off-by: Kai Huang <ahkcs@amazon.com>
|
Persistent review updated to latest commit d0cc903 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22611 +/- ##
============================================
- Coverage 71.39% 71.36% -0.04%
+ Complexity 76808 76741 -67
============================================
Files 6148 6148
Lines 357994 357994
Branches 52179 52179
============================================
- Hits 255607 255495 -112
- Misses 82054 82100 +46
- Partials 20333 20399 +66 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Thanks @ahkcs for working on this. I have an alternative proposal which I suspect should simplify the changes.
The operator rewrite should belong in the RBO planner layer (a new OpenSearchCheckedLongSumRule modeled on OpenSearchDistinctCountRule), not inside DataFusionFragmentConvertor. Moving it earlier, i.e., before OpenSearchAggregateRule runs means the entire stack sees SqlStdOperatorTable.SUM by operator identity: AggregateSplitRule, TopK, the Lucene backend, and Isthmus all resolve it correctly without any special-casing.
The custom LOCAL_CHECKED_LONG_SUM_OP, YAML bindings, and checked_long_sum.rs Rust UDAF are only needed in this PR because the current rewrite happens too late (inside the fragment convertor, after Isthmus dispatch). With an early planner rewrite, DataFusion receives sum in the Substrait proto and resolves to its own native sum_udaf — the delegation wrapper in checked_long_sum.rs is pure boilerplate with zero custom logic and could be deleted entirely.
Description
SQL PR opensearch-project/sql#5612 introduced the reflective
CHECKED_LONG_SUMaggregate. The analytics planner accepts it throughSqlKind.SUM, but Isthmus resolves Substrait bindings using the exact Calcite operator object and therefore could not bind it.This change adds a distinct
checked_long_sumSubstrait/runtime binding for aggregate and window calls. Its DataFusion UDAF delegates signatures, return types, grouped accumulators, and sliding accumulators to nativeSUM, preserving existing analytics semantics and performance.Keeping the function name distinct also avoids duplicate intermediate schema fields when a plan contains both
SUM(field)andCHECKED_LONG_SUM(field), such as AVG and SUM over the same column.Testing
cargo test --lib native_and_checked_sum_keep_distinct_names:sandbox:plugins:analytics-backend-datafusion:test --tests '*DataFusionFragmentConvertorTests'TopKCssCorrectnessIT.testCase08_avgSum_cssMatchesNoCssTopKCssCorrectnessIT.testCase10_noAliases_cssMatchesNoCssTopKCssCorrectnessIT.testCase11_manyAggsOnSameColumn_cssMatchesNoCssStatsCommandIT.testStatsIntegralSumStreamstatsCommandIT.testMultipleStreamstatsWithEvalStreamstatsCommandIT.testMultipleStreamstatsWithEval2:sandbox:plugins:analytics-backend-datafusion:precommit